<%@ page language="java" import="java.util.*,com.hs.auth.model.*,com.hs.wdss.model.*,com.hs.auth.*,java.sql.Clob" pageEncoding="utf-8"%>
<%
	WdssDisinfo obj = (WdssDisinfo)request.getAttribute("obj");
    WdssResource rsobj = (WdssResource)request.getAttribute("rsobj");
    Long wrid = rsobj.getId();
    String mrcode = obj.getDiscode(); 
    
    List dislist = (List)request.getAttribute("disnamelist");
    String dstypevalue = "";
    if(rsobj != null){
    	dstypevalue = rsobj.getDstype() + "";
    }
    boolean typeflag = true;
    if("2".equals(dstypevalue)){
    	typeflag = false;
    }
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="../../include.jsp"%>  
<script src="<%=basePath %>app/javascripts/transform.js"></script>
<script src='<%=basePath%>dwr/interface/dataProhelper.js'></script>  
<link rel="stylesheet" href="<%=basePath %>thirtpart/jquery/themes/base/jquery.ui.all.css"/>  
    <script src="<%=basePath %>thirtpart/jquery/ui/jquery.ui.core.js"></script> 
    <script src="<%=basePath %>thirtpart/jquery/ui/jquery.ui.widget.js"></script> 
    <script src="<%=basePath %>thirtpart/jquery/ui/jquery.ui.position.js"></script> 
    <script src="<%=basePath %>thirtpart/jquery/ui/jquery.ui.autocomplete.js"></script> 
    <link rel="stylesheet" href="<%=basePath %>thirtpart/jquery/themes/demos.css"/> 
    <link rel="STYLESHEET" type="text/css" href="<%=basePath %>thirtpart/dhtmlx25/dhtmlxcombo.css"/>
	
    <link rel="stylesheet" type="text/css" href="<%=basePath %>thirtpart/dhtmlx25/skins/dhtmlxlayout_dhx_blue.css"/>
    <script src="<%=basePath %>thirtpart/dhtmlx25/dhtmlxcommon.js"></script> 
	<script src="<%=basePath %>thirtpart/dhtmlx25/dhtmlxcontainer.js"></script>  
	<script  src="<%=basePath %>thirtpart/dhtmlx25/dhtmlxcombo.js"></script> 
    <script  src="<%=basePath %>thirtpart/dhtmlx25/ext/dhtmlxcombo_whp.js"></script>
    	<script  src="<%=basePath %>thirtpart/dhtmlx25/ext/dhtmlxcombo_extra.js"></script> 
    <script> 
    $(function() {
        $("#bookselect").autocomplete({
         delay: 0,
	     minLength:1, //表示输入多少个字才出现自动补全框    
	     select: function( event, ui ) {
				$( "#bookselect_value" ).val( ui.item.id );  
				changeBook();
				return false;
		 }  ,
	     source:function(request,response){
	      $.ajax(
	       {
	        url: '<%=basePath %>dict/ajaxcombox.do?db_table=WDSS_RESOURCE&col_id=id&col_name=BOOKNAME&condition=DSTYPE=1', 
	        dataType: "json", 
	        data: request, 
	        success:function(data){ 
	        	 response(data);  
	        }
	       }
	      );
	     }
     
    });
    
    $("#disname").autocomplete({
         delay: 0,
	     minLength:1, //表示输入多少个字才出现自动补全框  
	      
	     source:function(request,response){
	      $.ajax(
	       {
	        url: '<%=basePath %>dict/ajaxcombox.do?db_table=WDSS_STANDARD&col_id=id&col_name=STANDARDNAME&condition=CATEGORY='+encodeURIComponent('\'病名\''), 
	        dataType: "json", 
	        data: request, 
	        success:function(data){ 
	        	 response(data);  
	        }
	       }
	      );
	     }
     
    });
  });
  </script>
<script language="javascript" type="text/javascript">
 function downLoadFile(id){
 	window.location.href="<%=basePath%>produce/downloadFile.do?pid="+id;
 }   
 //医案信息相关方法
function savedata()
{
	/**var wdssid = document.getElementById("wdssid").value;   
 	var disname = document.getElementById("disname").value;  
	//var disname = bingming.getSelectedValue('disname');
	var curedate = document.getElementById("curedate").value; 
	var dishis = document.getElementById("dishis").value; 
	var maindesc = document.getElementById("maindesc").value; 
	var content = document.getElementById("content").value; 
	var chapter = document.getElementById("chapter").value; 
	var pagenum = document.getElementById("pagenum").value; 
	*/
	var dsid = '<%=obj == null?"0":obj.getDsid()%>';
	var discode = '<%=obj == null?"0":obj.getDiscode()%>'
	var wdssid = 	dwr.util.getValue("wdssid");   
 	var disname = dwr.util.getValue("disname");  
 	var curedate = dwr.util.getValue("curedate"); 
	var dishis = dwr.util.getValue("dishis"); 
	var maindesc = dwr.util.getValue("maindesc"); 
	var content = dwr.util.getValue("content"); 
	var chapter = dwr.util.getValue("chapter"); 
	var pagenum = dwr.util.getValue("pagenum"); 
    var r = /^[0-9]*[1-9][0-9]*$/　　//正整数 

    //str为你要判断的字符 执行返回结果 true 或 false
    
	if(!r.test(disname) || isNull(disname)) {
	   alert("请选择病名!"); 
	   return;
	}
	//alert("1:" + document.getElementById("disname").value); 
     dataProhelper.updateDis(wdssid,discode,maindesc,dishis,curedate,content,dsid,disname,chapter,pagenum,callback4addDis);
   // else
   //		dataProhelper.addDis(discode,maindesc,dishis,curedate,content,dsid,disname,chapter,pagenum,callback4addDis);
}

function callback4addDis(message){ 
    alert('医案信息保存成功！');  
    document.getElementById("wdssid").value = message;
    window.parent.datapromenu.document.all.wdssid.value = message;
    //刷新左边菜单
	window.parent.datapromenu.frameElement.src = "<%=basePath%>produce/datapromenu.do?wdssid="+message;
}
//医案来源信息相关方法(期刊)
function saveresourcedata()
{
	var resourceid = document.getElementById("resourceid").value; 
	var title = document.getElementById("title").value; 
	var maganame = document.getElementById("maganame").value; 
	var author = document.getElementById("author").value; 
	var keyword = document.getElementById("keyword").value; 
	var subjectword = document.getElementById("subjectword").value; 
	var abstract = document.getElementById("abstract").value; 
	var yearstr = document.getElementById("yearstr").value; 
	var rollstr = document.getElementById("rollstr").value; 
	var periodstr = document.getElementById("periodstr").value; 
	var pagestr = document.getElementById("pagestr").value; 
	if(isNull(title)){
		alert("请输入题名！");
		return; 
   	}
	if(!isNull(resourceid))
    	dataProhelper.updateResource(resourceid,title,maganame,author,keyword,subjectword,abstract,yearstr,rollstr,periodstr,pagestr,callback4addResource);
    else
   		dataProhelper.addResource(title,maganame,author,keyword,subjectword,abstract,yearstr,rollstr,periodstr,pagestr,callback4addResource);
}

function callback4addResource(message){ 
    alert('医案来源信息保存成功！');   
    document.getElementById("resourceid").value = message;
}
//医案来源信息相关方法(书籍)
function saveresourcedata2()
{
	var resourceid = document.getElementById("resourceid").value; 
	var bookname2 = document.getElementById("bookname2").value; 
	var author2 = document.getElementById("author2").value; 
	var publishunit2 = document.getElementById("publishunit2").value; 
	var keyword2 = document.getElementById("keyword2").value; 
	var subjectword2 = document.getElementById("subjectword2").value; 
	var abstract2 = document.getElementById("abstract2").value; 
	var publishaddress2 = document.getElementById("publishaddress2").value; 
	var publishdate2 = document.getElementById("publishdate2").value; 
	var banci2 = document.getElementById("banci2").value;
	var yinci2 = document.getElementById("yinci2").value;
	var zishu2 = document.getElementById("zishu2").value;
	var isbnstr2 = document.getElementById("isbnstr2").value; 
	if(isNull(bookname2)){
		alert("请先选择书籍名称！");
		return; 
   	}
 	if(!isNull(resourceid))
    	dataProhelper.updateResourceBook(resourceid,bookname2,author2,publishunit2,keyword2,subjectword2,abstract2,publishaddress2,publishdate2,banci2,yinci2,zishu2,isbnstr2,callback4addResource);
    else
   		dataProhelper.addResourceBook(bookname2,author2,publishunit2,keyword2,subjectword2,abstract2,publishaddress2,publishdate2,banci2,yinci2,zishu2,isbnstr2,callback4addResourceBook);
}

function callback4addResourceBook(message){ 
    alert('医案来源信息保存成功！');  
    document.getElementById("resourceid").value = message;
}
function changeBook(){
    
	var bookname = document.getElementById("bookselect_value").value;
	dataProhelper.selectBook(bookname,callback4selectBook);
}
function callback4selectBook(message){ 
    var data = eval('('+message+')');
    document.getElementById("bookname2").value =  data.bookname;
    document.getElementById("author2").value =  data.author;
    document.getElementById("publishunit2").value =  data.publishunit;
    document.getElementById("keyword2").value =  data.keyword;
    document.getElementById("subjectword2").value =  data.subjectword;
    document.getElementById("abstract2").value =  data.abstract;
    document.getElementById("publishaddress2").value =  data.publishaddress;
    document.getElementById("publishdate2").value =  data.publishdate;
    document.getElementById("isbnstr2").value =  data.isbnstr;
    document.getElementById("banci2").value =  data.banci;
    document.getElementById("yinci2").value =  data.yinci;
    document.getElementById("zishu2").value =  data.zishu;
    document.getElementById("resourceid").value =  data.id;
}
function backlist()
{
	window.parent.window.location.href = "<%=basePath%>produce/dataprolist.do";
}
function changeDstype(){
	var obj = document.getElementsByName("dstype");
	var dstype = "";
	for(var i=0;i<obj.length;i++){         
	    if(obj[i].checked){   
	         dstype = obj[i].value;         
	    }         
	} 
	if(dstype == "2"){
		document.getElementById("period").style.display = 'block';
		document.getElementById("book").style.display = 'none';
	}else if(dstype == "1"){
		document.getElementById("book").style.display = 'block';
		document.getElementById("period").style.display = 'none';
	} 

}
function doOnLoad() {
   
}
 function uploadfile(id){ 
 	openwindow("<%=basePath%>produce/uploadFile.do?id="+id,'600','400',''); 
 }
function downLoadFile(id){
 	window.location.href="<%=basePath%>produce/downloadFile.do?pid="+id;
}
function callback4FileDelete(data){  
	var tbody  = document.getElementById("listfile");// tbody 的id
   var rowobj = document.getElementById("file_"+data); 
   tbody.removeChild(rowobj);
}
function deleteFile(fileid){ 
	if(confirm("确认要删除该文档吗?")){
	    dataProhelper.deleteFile(fileid,callback4FileDelete);
	}        		
}	
function copydata(wrid,discode){
    dataProhelper.copydisdata('<%=wrid%>',discode,callback4copy);

}
function callback4copy(data){
    //alert(window.parent.location.href);
    alert("新增医案成功！");
	window.parent.location.href ="<%=basePath%>produce/dataPro.do?wdssid="+data;

}
</script>
</head>
<body scroll=yes onload="doOnLoad()">
	<div class="current">当前位置：数据加工 &gt; 医案信息</div>
     <div id="book" style="display:<%=typeflag?"":"none" %>">
		 <table border="0" cellspacing="0" cellpadding="0" class="news"> 
	        <caption>
	          医案来源信息（书籍）
	          </caption>
	          <tr>
	            <th width="15%">书名</th>
	            <td width="18%"><%=StringUtilTool.NULL2Blank(rsobj==null?"":rsobj.getBookname()) %>
	            </td>
	            <th width="15%">著者</th>
	            <td ><%=StringUtilTool.NULL2Blank(rsobj==null?"":rsobj.getAuthor()) %></td>
	            <th width="15%">出版社</th>
	            <td width="15%"><%=StringUtilTool.NULL2Blank(rsobj==null?"":rsobj.getPublishunit())%></td>
	          </tr> 
	        </table> 
        </div>
     <div id="period" style="display:<%=typeflag?"none":"" %>">
		 <table border="0" cellspacing="0" cellpadding="0" class="news"> 
	        <caption>
	          医案来源信息（期刊）
	          </caption>
	          <tr>
	            <th width="15%">刊名</th>
	            <td colspan=3><%=StringUtilTool.NULL2Blank(rsobj==null?"":rsobj.getMaganame()) %>
	           </td>
	            <th width="15%">题名</th>
	            <td><%=StringUtilTool.NULL2Blank(rsobj==null?"":rsobj.getTitle()) %></td>
	            <th width="15%">作者</th>
	            <td><%=StringUtilTool.NULL2Blank(rsobj==null?"":rsobj.getAuthor())%></td>
	          </tr>
	        </table> 
        </div>
        <table border="0" cellspacing="0" cellpadding="0" class="news"> 
        <caption>
          医案基本信息
          </caption>
          <tr>
            <th width="15%">医案编号</th>
            <td width="18%"><input type="text" name="discode" id="discode" value="<%=obj==null?"":obj.getDiscode() %>" style="width:97%" readonly/>
            <input name="wdssid" id="wdssid" type="hidden" value="<%=obj==null?"":obj.getId()%>"/>
           </td>
            <th width="15%">病名</th>
            <td width="18%">  
            <select   id="disname" name="disname" style='150px;'> 
                 <option value=""></option>
            	<%if(dislist != null){
            		for(int i =0;i<dislist.size();i++){
            			Map data = (Map)dislist.get(i);
            			String id = (String)data.get("ID");
            			String value = (String)data.get("VALUE");
            			out.print("<option value=");
            			out.print(id);
            			if(id.equals(obj.getDisname())){
            				out.print(" selected");
            			}
            			out.print(" >");
            			out.print(value);
            			out.println("</option>");
            		} 
            	} %>
            </select> 
</td>
            <th width="15%">就诊时间</th>
            <td width="18%"><input type="text" name="curedate" id="curedate" value="<%=StringUtilTool.NULL2Blank(obj==null?"":obj.getCuredate()) %>" style="width:97%"/></td>
          </tr>
          <tr>
            <th>病史</th>
            <td colspan=2><textarea name="dishis" id="dishis" rows=5 style="width:98%"><%=StringUtilTool.NULL2Blank(obj==null?"":obj.getDishis()) %></textarea></td>
            <th>主述</th>
            <td colspan=2><textarea name="maindesc" id="maindesc" rows=5 style="width:98%"><%=StringUtilTool.NULL2Blank(obj==null?"":obj.getMaindesc()) %></textarea></td>
          </tr> 
          <tr>
            <th  width="15%">章节</th>
            <td colspan=2><input type="text" name="chapter" id="chapter" value="<%=StringUtilTool.NULL2Blank(obj==null?"":obj.getChapter()) %>" style="width:97%"/></td>
            <th  width="15%">页数</th>
            <td colspan=2><input type="text" name="pagenum" id="pagenum" value="<%=StringUtilTool.NULL2Blank(obj==null?"":obj.getPagenum()) %>" style="width:97%"/></td>
          </tr>
          <tr>
            <th>原文文本</th>
            <td colspan=5 ><textarea name="content" rows=5 id="content" style="width:99%"><%
            	if(obj != null){
            		Clob clob = obj.getContent();
            		String contentStr = "";
				    if(clob != null)
				    	contentStr = clob.getSubString(1, (int)clob.length());
				    out.print(contentStr);
            	}
             %></textarea>
            </td> 
          </tr>
           <tr>
          	 
           <td colspan=6 align=center>
           		<input  type="button" value=" 保 存 " onclick="savedata();" class="butt"/>
                <input  type="button" value=" 返 回 " onclick="backlist();" class="butt"/>
                <input onclick="uploadfile('<%=obj.getId() %>')" type="button" value=" 原文上传 " class="but_3"/>
                <input  type="button" value=" 新增医案 " onclick="copydata('<%=wrid %>','<%=mrcode %>');" class="butt"/> 
           </td>
          </tr>
        </table>  
        <table border="0" cellspacing="0" cellpadding="0" style="width:100%" class="list">
          <caption>
          已上传原文附件
          </caption>
          <tr>
             <th>文件名称</th>
            <th width="10%">下载</th>
            <th width="10%">删除</th>
          </tr>
           <tbody id="listfile">
          <%
             if(null != obj.getFileset() && !(obj.getFileset().isEmpty())){
                   Iterator iter = obj.getFileset().iterator();
                   int i = 0;  
                   while(iter.hasNext()){
          	             WdssFile fileobj = (WdssFile)iter.next();
          	             i++; 
          	             Long fileid = fileobj.getId();
          	               
           %>
          <tr id="file_<%=fileid %>">
            <td><a href="javaScript:downLoadFile('<%=fileid %>')"><%=fileobj.getFilename() %></a> </td>
            <td><a href="javascript:onclick=downLoadFile('<%=fileid %>');">下载</a> </td>
            <td><a href="javascript:onclick=deleteFile('<%=fileid %>');">删除</a></td>
          </tr>
          <%}}else{ %> 
          </tbody>
          <%} %> 
           
        </table> 
        
</body>
</html>
<script language="javascript" type="text/javascript">
	 
	
	window.dhx_globalImgPath="<%=basePath %>thirtpart/dhtmlx25/imgs/"; 
	//var z=new dhtmlXCombo("book_div","bookselect",300);
	//var url = "<%=basePath %>dict/ajaxcombox.do?db_table=WDSS_RESOURCE&col_id=id&col_name=BOOKNAME&condition=DSTYPE=1";
	//z.enableFilteringMode(true,url,true,false);
	//z.enableOptionAutoPositioning(true);
	//z.enableFilteringMode(true);
	//z.loadXML(url);
	//z.readonly(false,true); 
	//z.attachEvent('onChange', changeBook);
	//病名选择
	
	var z = dhtmlXComboFromSelect("disname");
	z.enableFilteringMode(true);

 	//var bingming=new dhtmlXCombo("dis_div","disname",300);
	//var url = "<%=basePath %>dict/ajaxcombox.do?db_table=WDSS_STANDARD&col_id=id&col_name=STANDARDNAME&condition=CATEGORY="+encodeURIComponent('\'病名\'');
	//bingming.enableFilteringMode(true,url,true,false);
	//bingming.enableFilteringMode(true);
	//bingming.enableOptionAutoPositioning(true);
	//bingming.loadXML(url);
	//bingming.readonly(false,true); 
</script>



